package com.diamondfsd.jooq.controller;

import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static com.diamondfsd.jooq.methods.ChangeAndResetMethod.resetMethod;
import static com.diamondfsd.jooq.methods.SelectMethod.complexSelect;
import static com.diamondfsd.jooq.methods.SelectMethod.selectDemo;

public class main {
  public static void main(String[] args) {

    String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/learn-jooq?serverTimezone=GMT%2B8";
    String jdbcUsername = "root";
    String jdbcPassword = "";

    // 获取 JDBC 链接
    try (Connection connection = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword)) {
      // 获取 jOOQ 执行器
      DSLContext dslContext = DSL.using(connection, SQLDialect.MYSQL);
      /**
       * 打印数据库中数据
       */
      selectDemo(dslContext);
      complexSelect(dslContext);

      /**
       * CRUD
       */
//      insertByDSL(dslContext);
//      insertByRecord(dslContext);
//      updateByDSL(dslContext);
//      updateByRecord(dslContext);

      /**
       * ChangeAndReset
       */
      resetMethod(dslContext);

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }

}
